package com.kaifamiao.www.XML.do0930;

import com.kaifamiao.www.XML.do0929.Student;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.InputStream;
import java.util.List;

public class Demo {
    public static void main(String[] args) {

        InputStream inputStream = Demo.class.getClassLoader().getResourceAsStream("SQL.xml");
        SAXReader reader = new SAXReader();
        try {
            Document document = reader.read(inputStream);
            Element rootElement = document.getRootElement();
            Element selectElement = rootElement.element("select");
            String sql = selectElement.getTextTrim();
            String type = selectElement.attributeValue("type");
            System.out.println(type);
            Class cla = Class.forName(type);
            System.out.println(cla);
            qurey(sql,cla);
        } catch (DocumentException e) {
            e.printStackTrace();
        }
        catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
    public static void qurey(String sql,Class cla){
        List<Student> list = new DBUtil().query(sql,cla);
        for (Student student : list){
            System.out.println(student);
        }
    }
}
